﻿// See https://aka.ms/new-console-template for more information
using fastNpoi.Impl;
using fastNpoi.Interface;
using fastNpoi.Model;
using Microsoft.Extensions.DependencyInjection;
using NPOI.SS.UserModel;
using System.Diagnostics;
using test.Model;

Console.WriteLine("Hello, World!");
ServiceCollection serices = new ServiceCollection();
serices.AddScoped(typeof(IFastNpoi<>), typeof(FastNpoi<>));
var serviceProvider= serices.BuildServiceProvider();
var easyNpoi = serviceProvider.GetService<IFastNpoi<TestModel>>();
var list=new List<TestModel>(1000);
for(int i=0;i<2000; i++)
{
    TestModel item = new TestModel()
    {
        Id = i,
        Name = $"创建用的名称{i}",
        RandomNum = new Random().Next(),
        JsonStr="{\"name\":\"test\",\"value\":1}"
    };
    list.Add(item);
}
Stopwatch stopwatch = new Stopwatch();
//stopwatch.Start();
//easyNpoi.CreateWorkbook().CreateSheet().SetDataList(list).SetPageLimit(2000).SetDataOperation(new ExpressionOperation()).ToFile(@"C:\Users\tengfei8771\Desktop\excel");
//stopwatch.Stop();
//Console.WriteLine($"委托导出用时 {stopwatch.Elapsed}");
stopwatch.Restart();
easyNpoi.CreateWorkbook()
    .CreateSheet()
    .SetPageLimit(2000)
    .SetDataList(list)
    .SetColumnSkipNumber(2)
    .SetJsonMapping(t=>t.JsonStr,new Dictionary<string, string>()
    {
        {"json的姓名","name" },
        {"json的value","value" },
        {"虚拟列","test" }
    })
    .DataMapper(t =>
    {
        if (t.Id <=1000)
        {
            t.Id = 1000;
        }
        if (t.Id <= 2000 && t.Id >= 1500)
        {
            t.Id = 1500;
        }
        if (t.Id > 2500 && t.Id < 3000)
        {
            t.Id = 2500;
        }
        if (t.Id > 3000 && t.Id <= 3200)
        {
            t.Id = 3200;
        }
        
    })
    .ToFile(@"C:\Users\53205\Desktop\excel");
stopwatch.Stop();
Console.WriteLine($"反射导出用时 {stopwatch.Elapsed}");


